import java.util.*;


public class Schedule{
	ArrayList<course> courseList = new ArrayList<course>();
	ArrayList<Unique> uniqueList = new ArrayList<Unique>();
	// An array containing number of certain days
	// index 0 will represent MWF and 1 will represent TTH (more can be added later)
	int [] alldays;
	String endTime;
	String startTime;
	
	public Schedule()
	{
		
	}
	public Schedule(ArrayList<course> classes, ArrayList<Unique> uniques)
	{
		// days structure, sets MWF and TTH both to 0
		alldays = new int [2];
		//originally sets end time and start time to first then updates
		endTime = uniques.get(0).getTimes()[0].substring(5);
		startTime= uniques.get(0).getTimes()[0].substring(0,4);
		String [] times;
		String [] days;
		courseList=classes;
		for(int x=uniques.size()-1;x>=0;x--){
			uniqueList.add(uniques.get(x));
			times = uniques.get(x).getTimes();
			
			// adds days into alldays
			int j = 0;
			days = uniques.get(x).getDays();
			while(j < days.length && days[j] != null){
				if(days[j].equals("MWF"))
					alldays[0]++;
				else if(days[j].equals("TTH"))
					alldays[1]++;
				else if(days[j].equals("TH"))
					alldays[1]++;
				else if(days[j].equals("T"))
					alldays[1]++;
				else if(days[j].equals("M"))
					alldays[0]++;
				else if(days[j].equals("W"))
					alldays[0]++;
				else if(days[j].equals("F"))
					alldays[0]++;
				else if(days[j].equals("MW"))
					alldays[0]++;
				j++;
			}
			
			//sets end and start times
			int i = 0;
			while(i < times.length && times[i] != null){
				if(times[i].substring(0,4).compareTo(startTime) < 0)
					startTime = times[i].substring(0,4);
				if(times[i].substring(5).compareTo(endTime) > 0)
					endTime = times[i].substring(5);
				i++;
			}
		}
	}
	
	public void print()
	{
		//System.out.println(courseList);
		System.out.println(uniqueList);
		for(int x=0;x<uniqueList.size();x++)
		{
			Unique temp = uniqueList.get(x);
			//System.out.println(courseList.get(x)+" "+temp.getUniqueNumber());
		}
		
	}
	//returns true if a Schedule has a class with a certain professor
	public boolean hasProf(String prof)
	{
		for(int x=0;x<uniqueList.size();x++)
		{
			Unique u = uniqueList.get(x);
			if(u.getInstructor().toLowerCase().contains(prof.toLowerCase()))
				return true;
		}
		return false;
	}
	
	//if there is no time that conflicts with 12-1 then this returns true
	public boolean hasLunchBreak()
	{
		Unique lunch = new Unique(1,"No One","SAC","MWF","1200-1300");
		lunch.addDay("SAC","TTH","1200-1300");
		for(int x=0;x<uniqueList.size();x++)
		{
			Unique u = uniqueList.get(x);
			if(!u.compare(lunch))
				return false;
		}
		return true;
	}
	public String toString()
	{
		return uniqueList+"";
	}
	
	public String getEndTime(){
		return endTime;
	}
	
	public String getStartTime(){
		return startTime;
	}
}